<template>
	<view class="order">
		<view class="nav">

			<view class="title" :style="{height:titleHeight+'px'}">
				<view class="tit-top">
					<text>火车票预定</text>
				</view>
				<view class="tit-bot">
					<text>便携购票，服务您的每次出行</text>
				</view>
			</view>
		</view>
		<view class="center">
			<view class="center-top">
				<text class="left">
					{{valueleft}}
				</text>
				<image src="../../static/切换.png" class="cen" @click="changevalue" @change="chages">
				</image>
				<text class="right">
					{{valueright}}
				</text>
			</view>
			<view class="center-top">
				<text class="left" @click="open">
					{{years}}年{{month}}月{{day}}日 明日
				</text>
			</view>
			<view class="center-bot">
				<u-button text="查询" @click="order"></u-button>
			</view>
			<view class="center-his">
				<view class="left">
					<text>北京-上海</text>
				</view>
				<view class="right">
					<text>清除历史</text>
				</view>
			</view>
		</view>
		<view class="banner">
			<swiper class="swiper" :autoplay="true" :interval="3000" circular :duration="1000">
				<swiper-item class="swiper-item" v-for="(item,index) in banner" :key="index">
					<image :src="item"></image>
				</swiper-item>
			</swiper>
			<view class="newper">
				<uni-card margin="0" padding="0">
					<view class="title">
						<text slot="title">出行快讯</text>
						<text slot="actives">更多 ></text>
					</view>
					<dl v-for="(item,index) in newper" :key="index">
						<dd>
							<view class="newperleft">
								{{item.num}}
							</view>
							<view class="newperitem">
								<view class="newpercenter">
									{{item.title}}
								</view>
								<view class="newperright">
									{{item.date}}
								</view>
							</view>
						</dd>
						<dt>
							<image :src="item.img"></image>
						</dt>
					</dl>
				</uni-card>
			</view>
		</view>
		<uni-calendar ref="calendar" class="uni-calendar--hook" :clear-date="true" :date="info.date"
			:insert="info.insert" :lunar="info.lunar" :startDate="info.startDate" :endDate="info.endDate"
			:range="info.range" @confirm="confirm" @close="close" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navHeight: 50,
				titleHeight: 50,
				banner: [
					'https://www.bwie.net/statics/PCindex/images/index_banner1.jpg',
					'https://www.bwie.net/statics/PCindex/images/index_banner2.jpg',
					'https://www.bwie.net/statics/PCindex/images/index_banner3.jpg'
				],
				cover: 'https://web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',
				avatar: 'https://web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
				newper: [{
						id: 1,
						num: '1',
						title: `"五一" 假期7座小型客车免费通过全国收费公路`,
						date: '澎湃新闻 2022/04/27',
						img: 'https://www.bwie.net/statics/PCindex/images/index_banner1.jpg'
					},
					{
						id: 2,
						num: '2',
						title: `"五一" 假期7座小型客车免费通过全国收费公路`,
						date: '澎湃新闻 2022/04/27',
						img: 'https://www.bwie.net/statics/PCindex/images/index_banner1.jpg'
					},
					{
						id: 3,
						num: '3',
						title: `"五一" 假期7座小型客车免费通过全国收费公路`,
						date: '澎湃新闻 2022/04/27',
						img: 'https://www.bwie.net/statics/PCindex/images/index_banner1.jpg'
					},
					{
						id: 4,
						num: '4',
						title: `"五一" 假期7座小型客车免费通过全国收费公路`,
						date: '澎湃新闻 2022/04/27',
						img: 'https://www.bwie.net/statics/PCindex/images/index_banner1.jpg'
					}
				],
				valueleft: '北京',
				valueright: '上海',
				date: '2023-04-24',
				years: '2023',
				month: '4',
				day: '24'
			}
		},
		onLoad() {
			this.getmenu()
		},
		methods: {
			// 开启日期选择器
			open() {
				this.$refs.calendar.open()
			},
			close() {
				console.log('弹窗关闭');
			},
			// 执行回显
			confirm(e) {
				console.log('confirm 返回:', e.fulldate)
				this.date = e.fulldate
				this.years = e.fulldate.slice(0, 4)
				// 去零方法
				this.month = e.fulldate.substr(5, 2).replace(/\b(0+)/gi, '')
				this.day = e.fulldate.substr(8, 2).replace(/\b(0+)/gi, '')
				console.log('年', this.years);
				console.log('月', this.month);
				console.log('日', this.day);
			},

			// 点击切换城市
			changevalue() {
				// a b c 切换
				let cen = this.valueleft
				this.valueleft = this.valueright
				this.valueright = cen
			},
			// 获取 绛囊按钮位置
			getmenu() {
				let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
				this.navHeight = menuButtonInfo.top + 50
				this.titleHeight = menuButtonInfo.height + 130
				console.log(menuButtonInfo);
			},
			order() {
				uni.switchTab({
					url: '/pages/order/order'
				})
			}

		},

	}
</script>

<style lang="scss">
	.order {
		height: 100%;
		background-color: #eee;

		// position: relative;
		.nav {
			width: 130%;
			padding: 30rpx;
			background-color: #1BA9BA;
			position: absolute;
			left: -20%;

			.navitem {}

			border-radius: 0 0 30% 30%;

			.title {
				.tit-top {
					text {
						font-size: 40rpx;
						font-weight: bold;
					}
				}

				// text-align: center;
				text {

					display: inline-block;
					color: #ffffff;
					margin: 10rpx 200rpx;
				}
			}
		}

		.center {
			width: 95%;
			// height: 400rpx;
			background-color: #ffffff;
			position: absolute;
			top: 15%;
			padding: 55rpx;
			margin-top: 10px;
			margin-left: 2.5%;
			border-radius: 20rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.center-top {
				width: 95%;
				padding: 20rpx 0;
				display: flex;
				justify-content: space-between;
				border-bottom: 1px #ddd solid;
				font-weight: bold;

				.cen {
					width: 50rpx;
					background-color: #fff;
					height: 50rpx;
					line-height: 50rpx;
					border: none;
					outline: none;
				}
			}

			.center-bot {
				width: 95%;
				padding: 20rpx 0;
				font-weight: bold;

				button {
					border-radius: 50rpx;
					background-color: #FF8D41;
					color: #fff;
				}
			}

			.center-his {
				width: 90%;
				// padding: 25rpx 0;

				display: flex;
				justify-content: space-between;

				.left {
					color: #ccc;
				}

				.right {
					color: #aaa;
				}

				// text {
				// 	display: inline-block;
				// }
			}
		}

		.banner {
			padding: 690rpx 20rpx 0 20rpx;

			// padding: 20rpx;
			// position: absolute;
			// top: 52%;
			.swiper {
				// height: 60%;
				height: 150rpx;
				border-radius: 20rpx;
				overflow: hidden;

				.swiper-item {
					image {
						width: 100%;
						// height: 60%;
						// border-radius: 20rpx;
					}
				}
			}

			.newper {
				padding: 20rpx 0;

				.title {
					display: flex;
					justify-content: space-between;
					padding: 20rpx;
					border-bottom: 1px #ddd solid;

					text:nth-child(1) {
						font-size: 30rpx;
						font-weight: 700;
					}

					text:nth-child(2) {
						color: #aaa;
					}
				}

				dl {
					padding: 20rpx;
					display: flex;
					justify-content: space-between;
					border-bottom: 1px #ddd solid;

					dt {
						width: 40%;
						height: 110rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}

					dd {
						display: flex;

						// justify-content: space-between;
						.newperleft {
							padding: 0 20rpx;
							color: #f00;
							font-weight: 700;
							font-size: 30rpx;
						}

						.newperitem {
							display: flex;
							flex-direction: column;

							.newpercenter {
								width: 97%;
								font-weight: 700;
								font-size: 30rpx;
								text-indent: 1em;
							}

							.newperright {
								color: #aaa;
							}
						}
					}
				}
			}
		}
	}
</style>